package com.zhentao.day02.pm;

import java.util.*;

public class MapTest {
  public static void main(String[] args) {

    // 4. TreeMap
    // Map map = new Hashtable();
    // 基于 key 的自然排序 而排序。
    Map map = new TreeMap();
    // map.put(1, "a");
    // map.put(2, "b");
    // map.put(5, "c");
    // map.put(4, "d");
    // map.put(3, "e");
    Student stu1 = new Student(10000, "zhangsan", 18,"male",80);
    Student stu2 = new Student(10008, "wangwu", 20,"male",90);
    Student stu3 = new Student(10001, "lisi", 19,"male",99);
    Student stu4 = new Student(10009, "zhaoliu", 21,"fmale",95);

    map.put(stu1, 18);
    map.put(stu2, 20);
    map.put(stu3, 19);
    map.put(stu4, 21);

    Set set = map.entrySet();
    Iterator iterator = set.iterator();
    while (iterator.hasNext()) {
      Map.Entry entry = (Map.Entry) iterator.next();
      System.out.println("entry.getKey() : " + entry.getKey() + "\t entry.getValue() : " + entry.getValue());
    }

    // 5. Hashtable
    // Map map = new Hashtable();
    // map.put(1, "a");
    // map.put(2, "b");
    // map.put(4, "d");
    // map.put(3, "c");
    // System.out.println("map = " + map);

    // 3. map的遍历
    /*
    Student stu1 = new Student(10000, "zhangsan", 18,"male",80);
    Student stu3 = new Student(10086, "wangwu", 20,"male",90);
    Student stu2 = new Student(10001, "lisi", 19,"male",85);
    Student stu4 = new Student(10009, "zhaoliu", 21,"fmale",95);

    Map map = new LinkedHashMap();


    // Map map = new HashMap();
    map.put(stu1.getId(), stu1);
    map.put(stu3.getId(), stu3);
    map.put(stu2.getId(), stu2);
    map.put(stu4.getId(), stu4);

    Set<Map.Entry> set = map.entrySet(); // map.entrySet() 返回值是 Map.Entry 的Set集合
    // map集合的遍历方式
    for (Map.Entry entry : set) {
      System.out.println("\t entry.getKey() :" + entry.getKey()
          + "\t entry.getValue() :" + entry.getValue()
      );
    }*/



    /*Map map = new HashMap();
    map.put(stu1.getId(), stu1);
    map.put(stu2.getId(), stu2);
    map.put(stu3.getId(), stu3);
    map.put(stu4.getId(), stu4);


    // 遍历所有的键
    Set set = map.keySet();
    for (Object key : set) {
      int id = (int) key;
      System.out.println("key : \t" + id);
    }
    // 遍历所有的值
    Collection values =  map.values();
    for (Object value : values) {
      Student stu = (Student) value;
      System.out.println("value : \t" + stu);
    }*/

    // System.out.println("map = " + map);
    // map集合的 key 与 value 的同时遍历
    /*Set<Map.Entry> set = map.entrySet(); // map.entrySet() 返回值是 Map.Entry 的Set集合
    // map集合的遍历方式
    for (Map.Entry entry : set){
      System.out.println("\t entry.getKey() :" + entry.getKey()
        +"\t entry.getValue() :" + entry.getValue()
      );
    }*/


    // 2. map赋值
    /*Map map = new HashMap();
    map.put(null, "a"); // key值是可以存储null值的。
    map.put(1, "b");
    map.put(2, "c");

    System.out.println("map = " + map);*/


    // 1. 通过查看类图. 可以得到Map的实例有如下4种常用的Map集合。
    // Map map1 = new HashMap();
    // Map map2 = new TreeMap();
    // Map map3 = new Hashtable();
    // Map map4 = new LinkedHashMap();


  }
}
